package com.bk.ouat.service;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.bk.ouat.common.CommonProperties;
import com.bk.ouat.controller.UserController;
import com.bk.ouat.dao.UserDao;
import com.bk.ouat.dto.UserDto;


@Service
public class UserService {
	
	private static final Logger logger = LoggerFactory.getLogger(UserService.class);
	
	private final String NOT_FOUND_USER = "존재하지 않은 ID 입니다.";
	private final String PWD_NOT_MATCH = "비밀번호가 일치하지 않습니다.";
	
	@Autowired
	private UserDao userDao;
	
	@Autowired
	private CommonProperties commonProperties;

	public boolean isNotMatchPassword(UserDto userInfo) {
		// TODO Auto-generated method stub
		return false;
	}

	public boolean isNotFoundID(UserDto userInfo) {
		// TODO Auto-generated method stub
		return false;
	}

	public UserDto login(UserDto userInfo) {
		if(isNotFoundID(userInfo)){
			userInfo.setCode(commonProperties.getNotFountCode());
			userInfo.setCode_msg(NOT_FOUND_USER);
			return userInfo;
		}else if(isNotMatchPassword(userInfo)){
			userInfo.setCode(commonProperties.getRequestErrorCode());
			userInfo.setCode_msg(PWD_NOT_MATCH);
			return userInfo;
		}else{
			UserDto detailUserInfo = detail(userInfo);
			detailUserInfo.setCode(commonProperties.getOkCode());
			detailUserInfo.setCode_msg(commonProperties.getOkCodeMsg());
			return detailUserInfo;
		}
		
	}

	public void addUser(UserDto userInfo) {
		if(hasUserId(userInfo)){
			// skip
		}else{
			userDao.addUser(userInfo);
		}
	}
	
	public boolean hasUserId(UserDto userInfo){
		int checkCount = userDao.hasUserIdCount(userInfo);
		if(checkCount > 0){
			return true;
		}else{
			return false;
		}
	}

	@SuppressWarnings("rawtypes")
	public UserDto detail(UserDto userInfo) {
		return userDao.detailByMemberId(userInfo.getMember_id());
	}
}
